package com.bit.frige.sub.food;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.bit.frige.R;
import com.bit.frige.DB.DBContactHelper;
import com.bit.frige.DB.FoodDTO;
import com.bit.frige.DB.MyAdapter3;

public class SubFoodCateActivity extends Activity {
        ListView mList;
        ArrayList<FoodDTO> foodlist;
        private int place;
        MyAdapter3 adapter;

        @SuppressLint("NewApi")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_sub_food_cate);
//                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                Intent intent = getIntent();
                String centno = intent.getStringExtra("centno");
                place = intent.getIntExtra("place", 0);
                
                
                DBContactHelper db = new DBContactHelper(this);
                Log.d("카테고리","과연");
                mList = (ListView) findViewById(R.id.smallcate);
                foodlist = db.getFoodCategori(Integer.parseInt(centno));
                
                adapter = new MyAdapter3(this, foodlist);
                mList.setAdapter(adapter);
                
                
                
                mList.setOnItemClickListener(new OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int posion,
                                        long id) {
                                FoodDTO food = foodlist.get(posion);
                                Intent intent = new Intent(getApplicationContext(),SubFoodFormActivity.class);
                                intent.putExtra("id", food.getId());
                                intent.putExtra("cateno",food.getCateno());
                                intent.putExtra("foodname",food.getFoodname());
                                intent.putExtra("selflife",food.getSelflife());
                                intent.putExtra("place",place);
                                startActivity(intent);
                                
                                
                        }
                });
        }


}